<template>
  <div>
    <!-- readonly  shallowReadonly -->
    <h1>{{ obj.name }}</h1>
    <h1>{{ obj.boy.age }}</h1>
    <button @click="getValue">按钮</button>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, readonly, shallowReadonly } from "vue";

export default defineComponent({
  setup() {
    const obj = reactive({
      name: "tom",
      boy: {
        age: 16,
      },
    });
    // readonly只读属性 只能读不能更改
    const roObj = readonly(obj);
    // shallowReadonly 第一次只读不能更改，第二层第三次，是能更改
    const soObj = shallowReadonly(obj);
    const getValue = () => {
      console.log(obj.name);
      console.log(obj.boy.age);
      console.log(roObj.name);
      // roObj.a++;
      // roObj.b.c++;
      // soObj.a++;
      soObj.boy.age++;
    };
    return {
      obj,
      getValue,
    };
  },
});
</script>

<style scoped>

</style>